package com.ruoyi.common.bean;


import com.ruoyi.common.exception.global.BusinessErrorEnums;
import com.ruoyi.common.exception.global.IError;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * 请求结果
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultData<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;

//    public ResultData(Integer code, String msg, T data) {
//        this.status = code;
//        this.msg = msg;
//        this.data = data;
//    }

    public static ResultData ok() {
        return new ResultData(HttpStatus.OK.value(), "请求成功", null);
    }

    public static ResultData ok(Object data) {
        return new ResultData(HttpStatus.OK.value(), "请求成功", data);
    }

    public static ResultData error() {
        return new ResultData(BusinessErrorEnums.SYSTEM_INTERNAL_ERROR.getErrorCode(), "服务器繁忙，请稍后再试", null);
    }

    public static ResultData error(String msg) {
        return new ResultData(BusinessErrorEnums.SYSTEM_INTERNAL_ERROR.getErrorCode(), msg, null);
    }

    public static ResultData error(String msg, Integer code) {
        return new ResultData(code, msg, null);
    }

    public static ResultData error(IError error) {
        return new ResultData(error.getErrorCode(), error.getErrorMessage(), null);
    }
    public static ResultData error(Integer code, String msg, Object data) {
        return new ResultData(code, msg, data);
    }

    public static ResultData error(Integer code, String msg) {
        return new ResultData(code, msg, null);
    }

    public static ResultData ok(Integer code, String msg) {
        return new ResultData(code, msg, null);
    }
}
